'use strict';

var Model = require('../../config/models').roleModel;
var service = module.exports = {};

service.create = function(model) {
  return Model.create(model);
};

service.find = function(conditions, projection, options) {
  return Model.find(conditions, projection, options).exec();
};

service.remove = function(conditions ) {
  return Model.remove(conditions );
};

service.update = function(conditions, update) {
  return Model.update(conditions, update).exec();
};

service.findById = function(id) {
  return Model.findById(id).exec();
};

service.findOne = function(conditions) {
  return Model.findOne(conditions).exec();
};

service.findByIdAndUpdate = function(id, update, options) {
  return Model.findByIdAndUpdate(id, update, options).exec();
};

service.findByIdAndRemove = function(id, options) {
  return Model.findByIdAndRemove(id, options).exec();
};

service.defaultRole = function() {
  return this.findOne({defaultRole: true});
};

service.findByIdWithMenuOperator = function(id) {
  return Model.findById(id).populate([{path: 'purview.menu', select: {_id: 1, name: 1}}, {path: 'purview.operatorList', select: {_id: 1, name: 1}}]).exec();
};
